<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of home
 *
 * @author b4by
 */
class home extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this->data['is_home'] = true;
	}

	public function index() {

//		echo time()+60*60*24*10;die;

		$this->load->model('model_product');

		$product = $this->model_product->get_info($this->siteConfig->home_product);

		$this->data['product'] = $product;

		$this->load->model('model_catalogue');

		if (!$catalogues = $this->cache->file->get('home_catalogues')) {

			$catalogues = $this->model_catalogue->get_list($this->user_lang->id, array(
				'where' => array('home' => 1),
				'order' => array('index', 'asc')
					));

			foreach ($catalogues as &$cat) {
				$total_products = $this->model_product->get_total(array(
					'end >=' => now(),
					'l.location_id' => $this->location,
					'c.cat_id' => $cat->id,
					'active' => 1,
						));
				$cat->products = $this->model_product->get_list($this->user_lang->id, array(
					'where' => array('end >=' => now()),
					'limit' => array(0, 7),
					'order' => array('p.id', 'desc'),
						), $this->location, $cat->id);
				$cat->remaining_product = 0;
				if (count($cat->products) == 7)
					$cat->remaining_product = $total_products - 7;
			}
			$this->cache->file->save('home_catalogues', $catalogues, 30);
		}
		$this->data['catalogues1'] = $catalogues;

		$this->data['temp'] = 'home/index';
		$this->load_view();
	}

}

?>
